package com.haizhi.crm.sys.auth.dao;

import com.haizhi.crm.sys.auth.model.DepartmentDo;
import com.haizhi.crm.sys.auth.model.DepartmentVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yangyijun on 2018/5/10.
 */
@Repository
public interface DepartmentDao extends JpaRepository<DepartmentDo, Long> {

    /**
     * 根据经理id查询记录是否存在
     *
     * @param managerId
     * @return
     */
    @Query("select d.id from DepartmentDo d where d.managerId=:managerId" )
    Long findByManagerId(@Param("managerId" ) Long managerId);


    @Query("select new com.haizhi.crm.sys.auth.model.DepartmentVo" +
            "(d.id,d.name,d.directSuperiorDept) from DepartmentDo d where d.institutionId=:institutionId" )
    List<DepartmentVo> findByInstitutionId(@Param("institutionId" ) Long institutionId);
}
